<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<link rel="stylesheet" media="screen" href="${ctx}/css/docs.css" />
<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$(
								'input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea',
								'.form').iTextClear();
					});
</script>

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />

<script type="text/javascript"
        src="lib/datatables/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.3.custom.min.js"></script>
<script type="text/javascript" src="js/flexigrid.js"></script>
<link href="${ctx}/css/black-tie/jquery-ui-1.7.3.custom.css"
      rel="stylesheet" type="text/css"/>
      
<script type="text/javascript"
	src="lib/datatables/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="${ctx}/js/ajaxupload_tx.3.6.js"></script>
<!-- DATATABLES CSS END -->

<script>
	$(document).ready(function() {
		$('#simple-button').popover('#simple-popover', {});
		$('#top-button').popover('#top-popover', {
			preventLeft : true,
			preventRight : true,
			preventBottom : true
		});
	});
</script>
<div class="portlet grid_12 leading">
	<header>
		<h5 style="margin-bottom: 0px">
			前置数据包的完整度 <a href="#" id="total_progress">&nbsp;%</a>
		</h5>
	</header>
	<section id="import_uis">
		<table class="full">
			<tbody>
				<tr>
					<td style="width: 100px">考核</td>
					<td style="width: 50%"><div id="progress1" class="progress">
							<span style="width: 0%;"><b>0%</b></span>
						</div></td>
					<td style="width: 100px" class="ar">&nbsp;/&nbsp;</td>
					<td style="width: 400px" class="ar"><a
						href="#exam/statisticsview_main.xhtml?p=qual_browse" class="button"><span
							class="icon" style="background:url(${ctx}/images/img/error.png)">&nbsp;</span>查看</a></td>
				</tr>
				<tr>
					<td>ERP计件数据</td>
					<td><div class="progress">
							<span style="width: 0%;"><b>0%</b></span>
						</div></td>
					<td class="ar">&nbsp;/&nbsp;</td>
					<td class="ar"><a href="javascript:void(0)" id="erp_import_btn" class="button"><span
							class="icon" style="background:url(${ctx}/images/img/database_add.png)">&nbsp;</span>导入</a></td>
				</tr>
				<tr>
					<td>考勤数据</td>
					<td><div class="progress">
							<span style="width: 0%;"><b>0%</b></span>
						</div></td>
					<td class="ar">&nbsp;/&nbsp;</td>
					<td class="ar"><a href="#" class="button"
						id="attendance_import_btn"><span class="icon"
							style="background:url(${ctx}/images/img/database_add.png)">&nbsp;</span>导入</a></td>
				</tr>
			</tbody>
		</table>
	</section>
</div>
<div class="tabs side grid_12 leading">
	<div class="clear"></div>
	<div class="grid_12">
		<div class="form-action clearfix">
			<p>

				<a href="javascript:void(0)" class="button" onclick="computeSalary(this)"><span class="icon"
					style="background:url(${ctx}/images/img/calculator.png)">&nbsp;</span>结算所选范围的薪资</a>
			</p>
		</div>
	</div>
</div>
<div class="portlet grid_12 leading">
	<header>
		<h2>薪资结算结果报告</h2>
	</header>
	<section>
		<table class="basic-table">
			<tbody>
				<tr>
					<td>成功</td>
					<td class="ar"><span style="color: #3C0; font-weight: bold" id="span_success">0条</span></td>
				</tr>
				<tr>
					<td>失败</td>
					<td class="ar"><p style="color: #F00; font-weight: bold" id="span_failure">0条</p></td>
				</tr>
			</tbody>
		</table>
	</section>
</div>
<div class="clear"></div>
<div id="process_layer" style="width:400px; height:150px">
    <p>正在薪资计算中，请不要关闭窗口</p>
</div>


<script type="text/javascript" src="js/Tree.js"></script>
<!-- POPOVER SETUP-->
<script type="text/javascript" src="js/Tree.js"></script>
<script type="text/javascript">
	$(function() {
		AjaxUpload.init('${ctx}/ajax/attendance-data-import.xhtml', "attendance_import_btn", "", "");
        AjaxUpload.init('${ctx}/ajax/attendance-data-import.xhtml', "erp_import_btn", "", "");
        
        $("#process_layer").dialog(
        {
            autoOpen:false,
            height:200,
            width:450,
            modal:true,
            overlay:{
                backgroundColor:'#000',
                opacity:0.5
            }
        });
	});

	function onUploadSubmit(file, expand) {
		if (expand != "xls") {
			alert("文件类型不正确，请选择xls文件上传");
			return;
		}
	}
	function onUploadComplete(file, response) {
		//{"message":"filePath","result":"F:\\Projects\\ehr\\src\\main\\webapp\\WEB-INF\\pages\\temp\\2012-06-26\\1340725945119_Qaga_1101134.jpg","success":true}
		//alert("file=" + file + "**************" + response)
		var d;
		try {
			d = eval("[" + response + "]");
		} catch (err) {
			alert("文件上传错误！");
			return;
		}

		//var message = d[0].message;
		//上传出错
		if (d[0].success == false && d[0].result.length > 0) {
			alert(d[0].result);
            doSearch();
			return;
		}
		//上传成功
		else {
			alert("导入成功");
            doSearch();
		}
	}

	var callback;
	function computeSalary(evtObj){
		var mDate = new Date();
		if($("#search_year_" + currentTabOrgId).val()>=mDate.getFullYear()
				&& $("#search_month_" + currentTabOrgId).val() > mDate.getMonth()){
			alert("未到该月结算时间");
			return;
		}
		$("#process_layer").html("<p>正在薪资计算中，请不要关闭窗口</p>");
        $("#process_layer").dialog("open");
	    callback = setInterval("computeSalaryCallback()",1000);
		//提交数据 
		var url = "${ctx}/ajax/salary_compute.xhtml";
		 $.ajax(url, {
	            type : "POST",
	            data : {"organizationId":currentSelOrgId,
	            	"dutyId":$("#duty_sel_" + currentTabOrgId).val(),
	                "workId":$("#sel_employee_" + currentTabOrgId).val(),
	                "year":$("#search_year_" + currentTabOrgId).val(),
	                "month":$("#search_month_" + currentTabOrgId).val()
	            },
	            dataType : "json",
	            success : function(data) {
	            	alert('结算完毕');
            		$("#process_layer").html("<p>结算完毕</p>");
	            	if(callback != null){
	            		clearInterval(callback);
	                    $("#process_layer").dialog("close");
	                    setTimeout("computeSalaryCallback()",1000);
	            	}
	            },
	            error : function(XMLHttpRequest, textStatus, errorThrown) {
	            	alert("检测数据异常");
	            	$("#process_layer").html("<p>检测数据异常</p>");
	                if(callback != null){
	            		clearInterval(callback);
	                    //$("#process_layer").dialog("close");
	            	}
	            },
	            complete : function() {
	            }
	        });
	}
	
	function computeSalaryCallback(){
		//提交数据 
		var url = "${ctx}/ajax/salary_compute_callback.xhtml";
		 $.ajax(url, {
	            type : "get",
	            dataType : "html",
	            success : function(data) {
	            	if(data != null){
	            		var obj = eval("(" + data + ")");
	            		$("#span_success").html(obj.successCount + "条");
	            		$("#span_failure").html(obj.failureCount + "条");
	            	}
	            },
	            error : function(XMLHttpRequest, textStatus, errorThrown) {
	                //alert('检测数据异常');
	            },
	            complete : function() {
	            }
	        });
	}


    $(function(){
        doSearch();
    });

    function doSearch(){
        var year = $("#search_year_1").val();
        var month = $("#search_month_1").val();
        //alert(year+"***"+month)
        $.ajax("${ctx}/salary/attendance-import-log.xhtml", {
            type : "post",
            dataType : "html",
            data: {"organizationId":"${organizationId}", "year":year, "month":month},
            success : function(logs) {
                //alert(logs)
                $("#import_uis").html(logs);
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert('加载数据异常');
            },
            complete : function() {
            }
        });
    }
	
</script>